package gui;

import database.TMSDatabase;
import database.TableDatabaseUsage;
import info.Flight;

import javax.swing.table.AbstractTableModel;
import java.util.List;

public class ATM extends AbstractTableModel {
    private String[] columnNames = {"航班号","起飞站", "起飞时间", "到达站", "到达时间", "登机时间", "登机口"};
    public List<Flight> flightList = TableDatabaseUsage.getInstance().getFlightList();
    private static ATM instance = new ATM();
    public static ATM getInstance(){
        return instance;
    }

    @Override
    public int getRowCount() {
        return flightList.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Flight dataInfo = flightList.get(rowIndex);
        if(columnIndex == 0) {
            return dataInfo.getFlight();
        } else if(columnIndex == 1) {
            return dataInfo.getDEPA();
        } else if(columnIndex == 2) {
            return dataInfo.getDEPATime();
        } else if(columnIndex == 3) {
            return dataInfo.getDEST();
        } else if(columnIndex == 4) {
            return dataInfo.getDESTTIME();
        }else if(columnIndex == 5){
            return dataInfo.getBoarding();
        }else if(columnIndex == 6){
            return dataInfo.getGate();
        }
        return null;
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }

    public List<Flight> getFlightList() {
        return flightList;
    }
}
